package com.example.jishi.demos.web.controller;


import com.example.jishi.demos.web.entity.Employee; 
import com.example.jishi.demos.web.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/employees")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    @GetMapping("/list")
    public List<Employee> getAllEmployees(@RequestParam(name = "name", required = false)  String name) {
        return employeeService.getAllEmployees(name);
    }

    @GetMapping("/{id}")
    public Employee getEmployeeById(@PathVariable int id) {
        return employeeService.getEmployeeById(id);
    }

    @PostMapping("/add")
    public void addWorkLog(@RequestBody Employee employee) {
        employeeService.addEmployee(employee);
    }

    @PutMapping("/update")
    public void updateWorkLog(@RequestBody Employee employee) {
        employeeService.updateEmployee(employee);
    }

    @DeleteMapping("/delete/{id}")
    public void deleteEmployee(@PathVariable int id) {
        employeeService.deleteEmployee(id);
    }
}
